<template>
  <div id="CommentReply-container">
    <van-nav-bar :title="comment.reply_count ? comment.reply_count + '条回复' : '暂无回复'" @click-left="$emit('close')">
      <template #left>
        <div>
          <van-icon name="cross" size="18" class="nannsan" style="sda"></van-icon>
        </div>
      </template>
    </van-nav-bar>

    <!-- 评论中的评论列表 -->
    <comment-item :comment="comment" />
    <van-cell title="全部回复" />
    <comment-list type="c" :source="comment.com_id + ''" :list="list" />

    <!-- 点击进行评论 -->
    <div class="post-warp">
      <van-button round @click="showReply = true">评论</van-button>
    </div>

    <!-- 发布评论 -->
    <van-popup v-model="showReply" position="bottom">
      <!-- 对文章进行评论 -->
      <comment-post :target="comment.com_id + ''" :artId="$route.params.artId" @on-success="onSuccess" />
    </van-popup>
  </div>
</template>

<script>
import CommentItem from '@/components/CommentItem.vue'
import CommentList from './CommentList.vue'
import CommentPost from '@/views/Detail/components/CommentPost.vue'

export default {
  name: 'CommentReply',
  props: {
    comment: {
      type: Object,
      required: true
    }
  },
  components: {
    CommentItem,
    CommentList,
    CommentPost
  },
  data () {
    return {
      list: [],
      showReply: false
    }
  },
  created () {},
  methods: {
    onSuccess (e) {
      this.list.unshift(e)
      this.showReply = false
      this.comment.reply_count++
    }
  }
}
</script>

<style lang='less' scoped>
.post-warp {
  width: 100%;
  height: 100px;
  position: fixed;
  bottom: 0;
  border-top: 1px solid #ccc;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #ccc;
  .van-button {
    width: 640px;
    height: 80px;
  }
  .scroll-box {
    position: absolute;
    width: 100%;
    top: 92px;
    bottom: 100px;
    overflow-y: scroll;
  }
}
</style>
